/**
 * Copyright (c) 2013-2022 Nikita Koksharov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.redisson.client.protocol.convertor;


/**
 * 双重空安全重放转换器类，继承自DoubleReplayConvertor。
 * 该类的主要作用是在转换对象为Double类型时，提供空安全的处理机制。
 * 当转换结果为null时，默认返回0.0，以避免空指针异常。
 */
public class DoubleNullSafeReplayConvertor extends DoubleReplayConvertor {

    /**
     * 转换给定对象为Double类型，提供空安全机制。
     * 如果转换结果为null，则返回0.0。
     *
     * @param obj 待转换的对象。
     * @return 转换后的Double值，如果原对象无法转换为Double或转换结果为null，则返回0.0。
     */
    @Override
    public Double convert(Object obj) {
        Double r = super.convert(obj);
        if (r == null) {
            return 0.0;
        }
        return r;
    }

}

